
  <style type="text/css">
  	body{padding: 10px 30px;}
  	.hide{display:none}
  </style>

		<blockquote class="layui-elem-quote">注意：如果当前修改的管理员为系统拥有者，不可取消任何权限，因为拥有者默认开通全部权限</blockquote>
		<button id="save" class="layui-btn">保存</button>
		<table class="layui-table layui-form"  id="tree-table"></table>

		<script>
			layui.config({
				base: '/static/layui_extends/', 
			})
			layui.use(['treetable','iconPicker','form','laytpl'],function(){
				var $ = layui.$;
				var form = layui.form,layer = layui.layer,laytpl = layui.laytpl,iconPicker=layui.iconPicker;
				//var treetable ='';
				var layer_index;
				var aid = '{:input('param.aid')}';
				
				if(aid==1){
					layer.alert('您好，当前设置的用户为网站拥有者，默认拥有所有权限，改变任何权限都对其无效！');
				}
				
				var data= {$data};
				var checked = {$checked};
				for(var k in checked){
					checked[k]=Number(checked[k]);
				}
				for(var k in data){
					data[k].pid= 0;
				}
				treetable_render(data);
			
				//js渲染页面状态栏
				var nav_bar=[
				{"type":"menu","url":"/index/adminlist.html"},
				{"type":"url","url":"{:url('adminlist')}","title":"系统用户"},
				{"type":"url","url":"","title":"用户组-{:input('param.name')}"},
				]
				enianAdmin.render_nav_bar(nav_bar);
			
				
				//保存
				$('#save').click(function(){
					console.dir(treetable.all('checked'));
					var d = treetable.all('checked');
					$.ajax({
							type:"post",
							url:"{:url('',['t'=>'data'])}?type=1&aid="+enianAdmin.url().params.aid,
							data:{data:d.ids},
							async:true,
							success:function(r){
								// console.log(r);
								if(r.code==1){
									layer.msg('设置成功');
								}
								//treetable_render(data);
							}
						});
				})
			


				//-------------------------------------------------------------------------
				//重新加载菜单
				function treetable_reload(){
					layer.close(layer_index)
					window.location.reload()
//					$.ajax({
//							type:"post",
//							url:"{:url('setMenuLeft',['t'=>'data'])}?type=6",
//							//data:{ids:checked.ids},
//							async:true,
//							success:function(e){
//								treetable_render(e.data);
//							}
//						});
				}
				
				
				//渲染菜单
				function treetable_render(data){
					treetable = layui.treetable;
					treetable.render({
						elem: '#tree-table',
						data: data,
						field: 'name',
						is_checkbox :true,
						checked : checked,
						cols: [
							{	
								field: 'id',
								title: 'ID',
								width: '10%'
							},
							{
								field: 'name',
								title: '用户组名称',
								width: '30%',
							},
							{
								field: 'note',
								title: '备注',
								width: '60%',
							},
						]
					});
			
				}
				
				//加载编辑窗口
				function editWindow(elem,d,oldData){
					
					laytpl($(elem).html()).render(d, function(html){
						layer_index=layer.open({
						  type: 1,
						  skin: '', //加上边框
						  area: ['400px', '340px'], //宽高
						  content: html
						});
					});
				
				}
				
				
			})
			// console.log($data)
			
		</script>
